<?php
/**
 * Created by PhpStorm.
 * User: 10037
 * Date: 2022/6/12
 * Time: 16:28
 */

namespace app\admin\model;


use think\Model;

class Essaytable extends Model
{
    protected $pk='id';

    public function addEssay($title,$headImg,$table,$textInfo,$summary){
        $data['title']=$title;
        $data['headImg']=$headImg;
        $data['table']=$table;
        $data['textInfo']=$textInfo;
        $data['summary']=$summary;
        $data['addTime']=date('Y-m-d h:i:s',time());
        return $this->save($data);
    }

    public function selectEssay($page){
        return $this->where('delete','=',0)->page($page,5)->select();
    }

    public function deleteEssay($id){
        $result=$this->find($id);
        $result['delete']=1;
        return $result->save();
    }

    public function selectIdEssay($id){
        return $this->find($id);
    }

    public function updateEssay($id,$title,$headImg,$table,$textInfo,$summary){
        $result=$this->find($id);
        $result['title']=$title;
        $result['headImg']=$headImg;
        $result['table']=$table;
        $result['textInfo']=$textInfo;
        $result['summary']=$summary;

        return $result->save();
    }

    public function selectTextEssay($text){
       return $this->where('summary','like','%'.$text.'%')->select();
    }
}